package com.ynet.middleground.riskmanage.service.impl.qichacha;

import com.google.common.base.Throwables;
import com.ynet.core.common.ServiceResult;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.bean.qichacha.operationrisk.*;
import com.ynet.middleground.riskmanage.dto.qichacha.operationrisk.*;
import com.ynet.middleground.riskmanage.service.impl.GenericService;
import com.ynet.middleground.riskmanage.model.qichacha.OperationRiskModel;
import com.ynet.middleground.riskmanage.service.qichacha.OperationRiskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * @ClassName OperationRiskServiceImpl
 * @Description 企查查经营风险接口实现类
 * @Author zhangyongbin
 * @Date 2020/8/11 16:54
 * @Version 1.0
 */
@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Consumes({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Api(value = "企查查经营风险接口服务", tags = {"企查查经营风险接口服务"})
@Path("qcc")
@Service(timeout = 6000, version = "0.0.1")
public class OperationRiskServiceImpl implements OperationRiskService, GenericService {

    @Autowired
    OperationRiskModel operationRiskModel;

    @POST
    @Path("judicialsale")
    @ApiOperation(value = "司法拍卖核查", notes = "司法拍卖核查")
    @ApiImplicitParam(name = "requestObj", dataType = "JudicialSaleCheckReq", paramType = "body", required = true)
    @Override
    public ServiceResult<JudicialSaleCheckInfoDTO> getJudicialSaleCheckList(@Valid JudicialSaleCheckReq req) {
        ServiceResult<JudicialSaleCheckInfoDTO> result = new ServiceResult<>();

        try {
            result.setResult(operationRiskModel.getJudicialSaleCheckList(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "司法拍卖核查服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        result.setPagerInfo(req.getPagerInfo());
        return result;
    }

    @POST
    @ApiOperation(value = "土地抵押核查", notes = "土地抵押核查")
    @ApiImplicitParam(name = "requestObj", dataType = "LandMortgageCheckReq", paramType = "body", required = true)
    @Path("landmortgage")
    @Override
    public ServiceResult<LandMortgageCheckInfoDTO> getLandMortgageCheckList(@Valid LandMortgageCheckReq req) {
        ServiceResult<LandMortgageCheckInfoDTO> result = new ServiceResult<>();

        try {
            result.setResult(operationRiskModel.getLandMortgageCheckList(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "土地抵押核查服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        result.setPagerInfo(req.getPagerInfo());
        return result;
    }

    @POST
    @ApiOperation(value = "环保处罚核查", notes = "环保处罚核查")
    @ApiImplicitParam(name = "requestObj", dataType = "EnvPunishmentCheckReq", paramType = "body", required = true)
    @Path("envpunishment")
    @Override
    public ServiceResult<EnvPunishmentCheckInfoDTO> getEnvPunishmentCheckList(@Valid EnvPunishmentCheckReq req) {
        ServiceResult<EnvPunishmentCheckInfoDTO> result = new ServiceResult<>();

        try {
            result.setResult(operationRiskModel.getEnvPunishmentCheckList(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "环保处罚核查服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        result.setPagerInfo(req.getPagerInfo());
        return result;
    }

    @POST
    @ApiOperation(value = "获取严重违法信息", notes = "获取严重违法信息")
    @ApiImplicitParam(name = "requestObj", dataType = "SeriousIllegalCheckReq", paramType = "body", required = true)
    @Path("seriousIllegal")
    @Override
    public ServiceResult<SeriousIllegalCheckDTO> getSeriousIllegalCheckList(@Valid SeriousIllegalCheckReq req) {
        ServiceResult<SeriousIllegalCheckDTO> result = new ServiceResult<>();

        try {
            result.setResult(operationRiskModel.getSeriousIllegalCheckList(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "获取严重违法信息服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }

    @POST
    @ApiOperation(value = "获取动产抵押信息", notes = "获取动产抵押信息")
    @ApiImplicitParam(name = "requestObj", dataType = "ChattelMortgageCheckReq", paramType = "body", required = true)
    @Path("chattelMortgage")
    @Override
    public ServiceResult<ChattelMortgageCheckDTO> getChattelMortgageCheckList(@Valid ChattelMortgageCheckReq req) {
        ServiceResult<ChattelMortgageCheckDTO> result = new ServiceResult<>();

        try {
            result.setResult(operationRiskModel.getChattelMortgageCheckList(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "获取动产抵押信息服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }
}
